<?php

namespace plugin\ycMassage\process;

use plugin\ycMassage\app\model\MassageCouponCode;
use plugin\ycMassage\utils\enum\CouponCodeState;

class CouponExpire
{
    public function run()
    {
        try {
            $MassageCouponCode = MassageCouponCode::where(['state' => CouponCodeState::YES['value']])
                ->whereNotNull('end_time')
                ->whereTime('end_time', '<', date('Y-m-d H:i:s'))->select();
            foreach ($MassageCouponCode as $item) {
                $item->state = CouponCodeState::EXPIRED['value'];
                $item->save();
            }
        } catch (\Throwable $th) {
            p([$th->getMessage(), $th->getLine(), $th->getFile()],'MassageCouponExpire');
        }
    }
}
